<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/2/28
 * Time: 16:30
 */

namespace App\Http\Controllers\MiniProgram;


use App\Http\Logics\MiniProgram\TrainLogic;
use App\Http\Traits\TrainTrait;
use App\Http\Controllers\BaseController;
class TrainController extends BaseController
{
    use TrainTrait;

    /**
     * @SWG\POST(
     *     path="/train/create",
     *     tags={"Train"},
     *     description="发布培训",
     *     operationId="createTrain",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cafe_id",
     *         in="query",
     *         description="咖啡馆ID",
     *         type="integer",
     *         format="int32"
     *     ),
     *      @SWG\Parameter(
     *         name="name",
     *         in="query",
     *         description="培训名称",
     *         type="string"
     *     ),
     *      @SWG\Parameter(
     *         name="num",
     *         in="query",
     *         description="培训人数限制",
     *         type="integer",
     *         format="int32"
     *     ),
     *      @SWG\Parameter(
     *         name="cost",
     *         in="query",
     *         description="培训费用",
     *         type="integer",
     *         format="int32"
     *     ),
     *      @SWG\Parameter(
     *         name="link_man",
     *         in="query",
     *         description="联系人",
     *         type="string"
     *     ),
     *      @SWG\Parameter(
     *         name="mobile",
     *         in="query",
     *         description="联系方式",
     *         type="string"
     *     ),
     *      @SWG\Parameter(
     *         name="mark",
     *         in="query",
     *         description="备注",
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createTrain()
    {
        $cafe_id = $this->cafe_id;
        $name = $this->name;
        $num = $this->num;
        $cost = $this->cost;
        $link_man = $this->link_man;
        $mobile = $this->mobile;
        $mark = $this->mark;
        $data = [
            'cafe_id' => $cafe_id,
            'name' => $name,
            'num' => $num,
            'cost' => $cost,
            'link_man' => $link_man,
            'mobile' => $mobile,
            'mark' => $mark
        ];
        $response = TrainLogic::createTrain($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\POST(
     *     path="/train/update",
     *     tags={"Train"},
     *     description="更新培训",
     *     operationId="updateTrain",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="train_id",
     *         in="query",
     *         description="培训ID",
     *         type="integer",
     *         format="int32"
     *     ),
     *      @SWG\Parameter(
     *         name="name",
     *         in="query",
     *         description="培训名称",
     *         type="string"
     *     ),
     *      @SWG\Parameter(
     *         name="num",
     *         in="query",
     *         description="培训人数限制",
     *         type="integer",
     *         format="int32"
     *     ),
     *      @SWG\Parameter(
     *         name="cost",
     *         in="query",
     *         description="培训费用",
     *         type="integer",
     *         format="int32"
     *     ),
     *      @SWG\Parameter(
     *         name="link_man",
     *         in="query",
     *         description="联系人",
     *         type="string"
     *     ),
     *      @SWG\Parameter(
     *         name="mobile",
     *         in="query",
     *         description="联系方式",
     *         type="string"
     *     ),
     *      @SWG\Parameter(
     *         name="mark",
     *         in="query",
     *         description="备注",
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function updateTrain()
    {
        $train_id = $this->train_id;
        $cafe_id = $this->cafe_id;
        $name = $this->name;
        $num = $this->num;
        $cost = $this->cost;
        $link_man = $this->link_man;
        $mobile = $this->mobile;
        $mark = $this->mark;
        $data = [
            'train_id' => $train_id,
            'cafe_id' => $cafe_id,
            'name' => $name,
            'num' => $num,
            'cost' => $cost,
            'link_man' => $link_man,
            'mobile' => $mobile,
            'mark' => $mark
        ];
        $response = TrainLogic::updateTrain($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\POST(
     *     path="/train/delete",
     *     tags={"Train"},
     *     description="删除培训",
     *     operationId="deleteTrain",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="train_id",
     *         in="query",
     *         description="培训ID",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function deleteTrain()
    {
        $train_id = $this->train_id;
        $data = [
            'train_id' => $train_id
        ];
        $response = TrainLogic::deleteTrain($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\GET(
     *     path="/train/list",
     *     tags={"Train"},
     *     description="培训列表",
     *     operationId="getTrainList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cafe_id",
     *         in="query",
     *         description="培训ID",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getTrainList()
    {
        $cafe_id = $this->cafe_id;
        $limit = $this->limit;
        $status = $this->status;
        $data = [
            'cafe_id' => $cafe_id,
            'status' => $status,
            'limit' => $limit
        ];
        $response = TrainLogic::getTrainList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }


    /**
     * @SWG\Post(
     *     path="/train/changeStatus",
     *     tags={"Train"},
     *     description="改变培训信息的显示状态",
     *     operationId="changeStatus",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="train_id",
     *         in="query",
     *         description="培训ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function changeStatus()
    {
        $train_id = $this->train_id;
        $data = [
            'train_id' => $train_id
        ];
        $response = TrainLogic::changeStatus($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\GET(
     *     path="/train/detail",
     *     tags={"Train"},
     *     description="获取培训详情",
     *     operationId="getTrainDetail",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=false,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="train_id",
     *         in="query",
     *         description="培训ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getTrainDetail()
    {
        $train_id = $this->train_id;
        $data = [
            'train_id' => $train_id
        ];
        $response = TrainLogic::getTrainDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}